package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PartyMaterialTemplate;
import com.ruoyi.system.service.IPartyMaterialTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 党员材料模板Controller
 * 
 * @author ruoyi
 * @date 2025-10-19
 */
@RestController
@RequestMapping("/system/template")
public class PartyMaterialTemplateController extends BaseController
{
    @Autowired
    private IPartyMaterialTemplateService partyMaterialTemplateService;

    /**
     * 查询党员材料模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(PartyMaterialTemplate partyMaterialTemplate)
    {
        startPage();
        List<PartyMaterialTemplate> list = partyMaterialTemplateService.selectPartyMaterialTemplateList(partyMaterialTemplate);
        return getDataTable(list);
    }

    /**
     * 查询党员材料模板列表（移动端，不分页）
     */
    @GetMapping("/appList")
    public AjaxResult appList(PartyMaterialTemplate partyMaterialTemplate)
    {
        // 只查询状态正常的模板
        partyMaterialTemplate.setStatus("0");
        List<PartyMaterialTemplate> list = partyMaterialTemplateService.selectPartyMaterialTemplateList(partyMaterialTemplate);
        return AjaxResult.success(list);
    }

    /**
     * 导出党员材料模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:template:export')")
    @Log(title = "党员材料模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartyMaterialTemplate partyMaterialTemplate)
    {
        List<PartyMaterialTemplate> list = partyMaterialTemplateService.selectPartyMaterialTemplateList(partyMaterialTemplate);
        ExcelUtil<PartyMaterialTemplate> util = new ExcelUtil<PartyMaterialTemplate>(PartyMaterialTemplate.class);
        util.exportExcel(response, list, "党员材料模板数据");
    }

    /**
     * 获取党员材料模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:template:query')")
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long templateId)
    {
        return success(partyMaterialTemplateService.selectPartyMaterialTemplateByTemplateId(templateId));
    }

    /**
     * 新增党员材料模板
     */
    @PreAuthorize("@ss.hasPermi('system:template:add')")
    @Log(title = "党员材料模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartyMaterialTemplate partyMaterialTemplate)
    {
        return toAjax(partyMaterialTemplateService.insertPartyMaterialTemplate(partyMaterialTemplate));
    }

    /**
     * 修改党员材料模板
     */
    @PreAuthorize("@ss.hasPermi('system:template:edit')")
    @Log(title = "党员材料模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartyMaterialTemplate partyMaterialTemplate)
    {
        return toAjax(partyMaterialTemplateService.updatePartyMaterialTemplate(partyMaterialTemplate));
    }

    /**
     * 删除党员材料模板
     */
    @PreAuthorize("@ss.hasPermi('system:template:remove')")
    @Log(title = "党员材料模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] templateIds)
    {
        return toAjax(partyMaterialTemplateService.deletePartyMaterialTemplateByTemplateIds(templateIds));
    }
}
